﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include<QIcon>
#include<QMenuBar>
#include<QAction>
#include<QPushButton>
#include<QWidget>
#include<QObject>
#include<QMouseEvent>
#include<QPixmap>
#include<QPainter>
#include<Qpoint>
#include<QVector>

#include <QIcon>
#include <QMenuBar>
#include <QAction>
#include <QPushButton>
#include <QWidget>
#include <QObject>
#include <QPainter>
#include <QMouseEvent>
#include <QVector>
#include <QRect>
#include <QDebug>
#include<QGraphicsItem>
#include<QGraphicsSceneWheelEvent>
#include<QGraphicsView>
#include<QGraphicsView>
#include<iostream>
#include<QFileDialog>
#include<QTextEdit>
#include<QImage>
#include<QKeyEvent>
#include<QWheelEvent>
#include<QColor>
#include<QColorDialog>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QVector>
#include <QMessageBox>
using namespace std;


QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

struct Shape {
    enum Type { None, Line, Rectangle, Circle, Ellipse,Curve };

    Type type;
    QRect rect;
    QColor lineColor;
    bool isSelected;

    Shape(Type t, QRect r, QColor lc) : type(t), rect(r), lineColor(lc), isSelected(false) {}
};



class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void addShape(Shape::Type type, QRect rect, QColor lineColor)
    {
        shapes.append(Shape(type, rect, lineColor));
    }

protected:
    virtual void mousePressEvent(QMouseEvent *event);
    virtual void mouseReleaseEvent(QMouseEvent *event);
    //virtual void mouseDoubleClickEvent(QMouseEvent *event);
    virtual void mouseMoveEvent(QMouseEvent *event);
    virtual void keyPressEvent(QKeyEvent * event);
    virtual void wheelEvent(QWheelEvent * event);


public:
    QPoint start;
    QPoint end;
    QPixmap* pix;
    void paintEvent(QPaintEvent *event);
    QVector<QPoint> _line;
    bool save;
    bool isSelected = false;
    //void wheelEvent(QGraphicsSceneWheelEvent * event);
    qreal m_scaleValue = 1;//当前缩放倍数
    qreal m_scaleDefault = 1;//默认缩放倍数
    int currentWidth;
    int currentHeight;
    int currentLeft;
    int currentRight;
    int currentTop;
    int currentBottom;
    int _drawType;
    int _openflag;
    QPixmap _pixmap;
    QTextEdit *_tEdit;
    QImage *image;
    // 保存绘图内容到文件
    bool saveDrawingToFile(const QString &fileName);
    // 从文件加载绘图内容
    bool loadDrawingFromFile(const QString &fileName);


public:
    int type;//判断绘制类型
    double r;//圆的半径
    QVector<Shape> shapes;
    QColor color;
    double width;
    Qt::PenStyle style;
private:
    Shape* selectedShape; // 用于跟踪选中的图形
    Shape::Type selectedShapeType;
    QColor selectedLineColor;
    bool m_pressFlag;
    QVector<QPoint>m_points;
    QString str;

    QList<QColor> m_colors;
    QList<int> m_widths;
    QList<Qt::PenStyle> m_penStyles;

signals:

public slots:
    void Line();//直线
    void Rect();//矩形
    void Circle();//圆
    void Ellipse();//椭圆
    void Curve();
    void ClearPainter();//清除画布
    void Large();//放大
    void Small();//缩小
    void Left();//左移
    void Right();//右移
    void Up();//上移
    void Down();//下移
    void OpenPic();//打开图片
    void SavePic();//保存图片
    void SetColor();//颜色
    void SetWidth1();//粗细
    void SetWidth2();
    void SetWidth3();
    void SetStyle1();//样式
    void SetStyle2();
    void SetStyle3();
    void Copy();//复制


private:
    Ui::MainWindow *ui;

};
#endif // MAINWINDOW_H
